//
//  Tab1CV.m
//  OCProject
//
//  Created by 王明钦 on 2018/2/9.
//  Copyright © 2018年 oc. All rights reserved.
//

#import "Tab1CV.h"
#import "Tab2CV.h"
#import "RegisterCV.h"
#import "HomeBookCell.h"
#import "WeixinModel.h"
//分页显示 每页数据容量
#define LIMITCOUNT 10
static NSString * const HomeBookCellReuseIdentifier = @"HomeBookCell";

@interface Tab1CV ()<UITableViewDelegate, UITableViewDataSource>

@property(nonatomic, strong) UITableView *tabview;
@property(nonatomic, strong) NSMutableArray *dataArray;

@property(nonatomic, assign) NSInteger pageNo;

@end

@implementation Tab1CV

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
//    [self setMainTitle:@"TAB1"];
    
    self.tabview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KSCREENWIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    self.tabview.delegate = self;
    self.tabview.dataSource = self;
    [self.view addSubview:self.tabview];
    
   UINib *nib = [UINib nibWithNibName:HomeBookCellReuseIdentifier bundle:nil];
//    UINib *nib = [UINib nibWithNibName:HomeBookCellReuseIdentifier bundle:nil]
    [self.tabview registerNib:nib forCellReuseIdentifier:HomeBookCellReuseIdentifier];
    
    self.dataArray = [NSMutableArray array];

    NSDictionary *parms = @{
                            
                            @"pno": [NSNumber numberWithInteger:_pageNo],
                            @"ps": @LIMITCOUNT,
                            @"dtype": @"",
                            @"key": @"799b785ba7b97223be80534651dd0d63"
                            
                            };
    
    RYDBaseApi *api = [[RYDBaseApi alloc] init];
    api.requestMethod = RTLRequestMethodGET;
    //        api.requestURL = @"v2/movie/in_theaters";
    api.requestURL = @"/weixin/query";
    
    api.requestParameters = parms;
    //        api.requestConstructionCallback = ^(id<AFMultipartFormData> formData){
    //            formData =  [self postFormDataWithNames:@[@"userId"] params:parms formData:formData];
    //        };
    [api startRequestSuccessCallback:^(__kindof RTLBaseRequest *request, id responseObject) {
        NSLog(@"responseObject");
        id result = [responseObject objectForKey:@"result"];
        id list = [result objectForKey:@"list"];
        self.dataArray = [WeixinModel mj_objectArrayWithKeyValuesArray:list];
        
        [self.tabview reloadData];
        
    } failureCallback:^(__kindof RTLBaseRequest *request, NSError *error) {
        
    }];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    return self.dataArray.count;
    return self.dataArray.count;

}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WeixinModel *item = self.dataArray[indexPath.row];
    HomeBookCell *cell = [tableView dequeueReusableCellWithIdentifier:HomeBookCellReuseIdentifier];
    cell.tvTitle.text = item.title;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

-(BOOL)isNeedHeader{
    return NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
